package com.ruoyi.web.controller.depot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.depot.domain.vo.AddInventoryTaskVO;
import com.ruoyi.depot.domain.vo.InventoryProductVO;
import com.ruoyi.depot.service.ILocalInventoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.depot.domain.Stocktakes;
import com.ruoyi.depot.service.IStocktakesService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点任务Controller
 * 
 * @author luxiaoyu
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/depot/stocktakes")
public class StocktakesController extends BaseController
{
    @Autowired
    private IStocktakesService stocktakesService;

    @Autowired
    private ILocalInventoryService localInventoryService;

    /**
     * 查询盘点任务列表
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:list')")
    @GetMapping("/list")
    public TableDataInfo list(Stocktakes stocktakes)
    {
        startPage();
        List<Stocktakes> list = stocktakesService.selectStocktakesList(stocktakes);
        return getDataTable(list);
    }

    /**
     * 导出盘点任务列表
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:export')")
    @Log(title = "盘点任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Stocktakes stocktakes)
    {
        List<Stocktakes> list = stocktakesService.selectStocktakesList(stocktakes);
        ExcelUtil<Stocktakes> util = new ExcelUtil<Stocktakes>(Stocktakes.class);
        util.exportExcel(response, list, "盘点任务数据");
    }

    /**
     * 获取盘点任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:query')")
    @GetMapping(value = "/{stocktakeId}")
    public AjaxResult getInfo(@PathVariable("stocktakeId") String stocktakeId)
    {
        return success(stocktakesService.selectStocktakesByStocktakeId(stocktakeId));
    }

    /**
     * 查询新增库存盘点中添加产品信息
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:query')")
    @GetMapping(value = "/productList")
    public TableDataInfo getSelectProductList(InventoryProductVO vo)
    {
        startPage();
        return getDataTable(localInventoryService.selectProductListByWarehouseId(vo));
    }

    /**
     * 新增盘点任务
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:add')")
    @Log(title = "盘点任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddInventoryTaskVO addInventoryTaskVO)
    {
        return toAjax(stocktakesService.insertStocktakes(addInventoryTaskVO));
    }

    /**
     * 修改盘点任务
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:edit')")
    @Log(title = "盘点任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Stocktakes stocktakes)
    {
        return toAjax(stocktakesService.updateStocktakes(stocktakes));
    }

    /**
     * 删除盘点任务
     */
    @PreAuthorize("@ss.hasPermi('depot:stocktakes:remove')")
    @Log(title = "盘点任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stocktakeIds}")
    public AjaxResult remove(@PathVariable String[] stocktakeIds)
    {
        return toAjax(stocktakesService.deleteStocktakesByStocktakeIds(stocktakeIds));
    }
}
